home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Demos / OOFILE / Buildable, limited OOFILE / OOFILE partial source / oofview.cpp < prev   
Encoding:
Text File  |  1995-09-24  |  3.1 KB  |  179 lines  |  [TEXT/CWIE]

  1. // COPYRIGHT 1994 A.D. Software, All rights reserved
  2.  
  3. // public layer of OOFILE database - database views
  4.  
  5. #include "oof3.hpp"  // knows a bit about fields
  6. #include "oofrel.hpp"  // knows about relations
  7. #include "oofview.hpp"
  8.  
  9. // -------------------------------------------------------
  10. //                     d b V i e w
  11. // -------------------------------------------------------
  12.  
  13. dbView::dbView(dbTable*    tbl)
  14. {
  15.     mSource = new dbSourceTable(tbl);
  16.     assert(mSource);
  17. }
  18.  
  19.  
  20. dbView::dbView(dbTable&    tbl)
  21. {
  22.     mSource = new dbSourceTable(&tbl);
  23.     assert(mSource);
  24. }
  25.  
  26.  
  27. dbView::dbView(dbRelRefBase* tblRef)
  28. {
  29.     mSource = new dbSourceRelTable(tblRef);
  30.     assert(mSource);
  31. }
  32.  
  33.  
  34. dbView::dbView(dbRelRefBase& tblRef)
  35. {
  36.     mSource = new dbSourceRelTable(&tblRef);
  37.     assert(mSource);
  38. }
  39.  
  40.  
  41. dbView::dbView(const dbView& rhs) : 
  42.                 OOF_Dictionary(rhs)
  43. {
  44.     mSource = rhs.mSource->clone();
  45. }
  46.  
  47.  
  48. const dbView& dbView::operator=(const dbView& rhs)
  49. {
  50.     if (this == &rhs)
  51.         return *this;
  52.     
  53.     delete mSource;
  54.     mSource = rhs.mSource->clone();
  55.     return *this;
  56. }
  57.  
  58.  
  59. dbView::~dbView()
  60. {
  61.     delete mSource;
  62. }
  63.  
  64.  
  65. dbField& dbView::field(unsigned int fieldNoInView)
  66. {
  67.     dbField* theField = (dbField*) item(fieldNoInView);  // safe downcast
  68.     return *theField;
  69. }
  70.  
  71.  
  72. ostream& operator<<(ostream& os, dbView& theView)
  73. {
  74.     theView.source()->start();
  75.     unsigned long numRecs = theView.source()->count();
  76.    unsigned int numFields = theView.count();
  77.     for (unsigned long row=0; row<numRecs; row++) {    // iterate through records (vertical)
  78.         for (unsigned int col=0; col<numFields; col++) {        // start field iteration (horizontal)
  79.             dbField  *theField = (dbField *) theView[col];           // safe downcast
  80.             theField->extract(os);
  81.             os << '\t';
  82.         }
  83.         os << endl;
  84.         theView.source()->next();
  85.     }
  86.     return os;
  87. }
  88.  
  89.  
  90.  
  91. // -------------------------------------------------------
  92. //               d b S o u r c e T a b l e 
  93. // -------------------------------------------------------
  94. dbSource* dbSourceTable::clone() const
  95. {
  96.     return new dbSourceTable(*this);
  97. }
  98.  
  99.  
  100. void dbSourceTable::next()
  101. {
  102.     mTable->next();
  103. }
  104.  
  105.  
  106. unsigned long dbSourceTable::count()
  107. {
  108.     return mTable->count();
  109. }
  110.  
  111.  
  112. void dbSourceTable::saveRecord()
  113. {
  114.     mTable->saveRecord();
  115. }
  116.  
  117.  
  118. void dbSourceTable::newRecord()
  119. {
  120.     mTable->newRecord();
  121. }
  122.  
  123.  
  124. bool dbSourceTable::gotoRelativeRecord(unsigned long recNo)
  125. {
  126.     return mTable->gotoRelativeRecord(recNo);
  127. }
  128.  
  129.  
  130. // -------------------------------------------------------
  131. //          d b S o u r c e R e l T a b l e 
  132. // -------------------------------------------------------
  133. void dbSourceRelTable::start()
  134. {
  135.     mTableRef->start();
  136. }
  137.  
  138.  
  139. bool dbSourceRelTable::more()
  140. {
  141.     return mTableRef->more();
  142. }
  143.  
  144.  
  145. void dbSourceRelTable::next()
  146. {
  147.     mTableRef->next();
  148. }
  149.  
  150.  
  151. unsigned long dbSourceRelTable::count()
  152. {
  153.     return mTableRef->count();
  154. }
  155.  
  156.  
  157. void dbSourceRelTable::saveRecord()
  158. {
  159.     dbConnect::raise("saveRecord has been called on a view which has a dbSourceRelTable");
  160. }
  161.  
  162.  
  163. void dbSourceRelTable::newRecord()
  164. {
  165.     mTableRef->newRecord();
  166. }
  167.  
  168.  
  169. dbSource* dbSourceRelTable::clone() const
  170. {
  171.     return new dbSourceRelTable(*this);
  172. }
  173.  
  174.  
  175. bool dbSourceRelTable::gotoRelativeRecord(unsigned long recNo)
  176. {
  177.     return mTableRef->gotoRelativeRecord(recNo);
  178. }
  179.